//
//  UpdatePhoneViewController.m
//  CarTown
//
//  Created by xionghao on 15/9/2.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "UpdatePhoneViewController.h"
#import "Puser.h"
#import "UserInfoUpdateResde.h"
#import "PersonalRegStep1ViewController.h"
@interface UpdatePhoneViewController ()
@property (weak, nonatomic) IBOutlet UILabel *phonenumber;
@property (weak, nonatomic) IBOutlet UITextField *password;

@property (nonatomic,strong) Puser *user;

@end

@implementation UpdatePhoneViewController
+(instancetype)Viewcontroller{
    UpdatePhoneViewController *vc=[[UpdatePhoneViewController alloc]initWithNibName:NSStringFromClass([self class]) bundle:nil];
    return vc;
}

-(Puser *)user{
    if (_user==nil) {
        _user=[Puser getUser];
    }
    return _user;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"验证密码";
    
    self.phonenumber.text=self.user.user_mobile;
    
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)next:(id)sender {
    
    if ([self checkform]) {
        
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"正在验证..";
        
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        NSMutableDictionary *params=[NSMutableDictionary  dictionary];
        params[@"action"]=@"p_phone_check";
        params[@"user_type"]=@"person";
        params[@"user_id"]=self.user.user_id;        params[@"passwd"]=self.password.text;
        params[@"phone"]=self.user.user_mobile;
        [PostUitls Post:userinfourl parameters:params success:^(id response) {
            NSLog(@"%@",response);
            UserInfoUpdateResde *resmode=[UserInfoUpdateResde resdeWithDict:response];
            
            hud.mode=MBProgressHUDModeText;
            
            
            if ([resmode.state integerValue]==400) {
                NSLog(@"%@",resmode);
                [hud hide:YES];
                [self pustoValidate];
            }else{
                hud.labelText=@"验证失败";
                [hud hide:YES afterDelay:1];
            }
        } failure:^(NSError *error) {
            hud.mode=MBProgressHUDModeText;
            hud.labelText=@"网络错误";
            [hud hide:YES afterDelay:1];
        }];
        
    }
}
-(void)pustoValidate{
    PersonalRegStep1ViewController *regvc=[XHMianStory instantiateViewControllerWithIdentifier:@"reg1vc"];
    regvc.pass=self.password.text;
    [self.navigationController pushViewController:regvc animated:YES];
}
-(BOOL)checkform{
    if (self.password.text.length==0) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"密码不能为空";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        
        return NO;
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
